package com.axin.blog.controller;

import com.axin.blog.api.domain.BlogCategory;
import com.axin.blog.api.domain.BlogComment;
import com.axin.blog.api.vo.BlogCommentVo;
import com.axin.blog.service.IBlogCategoryService;
import com.axin.blog.service.IBlogCommentService;
import com.axin.common.core.domain.web.AjaxResult;
import com.axin.common.core.domain.web.TableDataInfo;
import com.axin.common.security.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 博客评论 接口控制
 *
 * @Author axin
 * @Date 2021/10/29 17:10
 **/
@RestController
@RequestMapping("/comment")
public class BlogCommentController extends BaseController {

    @Autowired
    private IBlogCommentService commentService;


    /**
     * 根据参数分页查询博客评论列表
     */
    @PreAuthorize("@ss.hasPermi('blog:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlogComment comment) {
        return commentService.selectPageBlogCommentList(comment);
    }

    /**
     * 删除评论
     */
    @PreAuthorize("@ss.hasPermi('blog:comment:remove')")
    @DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds) {
        commentService.deleteBlogCommentByIds(commentIds);
        return success();
    }

    /************************前台接口******************************************************************************************/


    /**
     * 查询评论列表
     *
     * @param pageNum
     * @param pageSize
     * @param blogId
     * @return
     */
    @GetMapping("/getCommentList")
    public TableDataInfo<BlogCommentVo> getCommentList(@RequestParam("pageNum") Integer pageNum,
                                                       @RequestParam("pageSize") Integer pageSize,
                                                       @RequestParam("blogId") Long blogId) {
        return commentService.selectBlogCommentList(blogId);
    }

    @PostMapping("/comment")
    public AjaxResult comment(@RequestBody  BlogComment comment) {
        commentService.insertBlogComment(comment);
        return success();
    }



}
